<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/1/21
  Time: 15:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>addBook</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<body>
    <form id="addBook" class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">图书名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图书价格</label>
            <div class="layui-input-block">
                <input type="text" name="price" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图书状态</label>
            <div class="layui-input-block">
                <input type="radio" name="state" value="0" title="上架" checked>
                <input type="radio" name="state" value="1" title="下架">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出版时间</label>
            <div class="layui-input-block">
                <input type="text" name="press_date" id="test1" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>

        layui.use(['form','laydate'],function () {
            var form = layui.form;
            var laydate = layui.laydate;
            var $ = layui.$;

            laydate.render({
                elem:'#test1'
            })
            form.on('submit(add)',function () {
                alert("bbb")
                $.ajax({
                    url:'book/addBook',
                    data:$("#addBook").serialize(),
                    success:function () {
                        alert('添加成功')
                    }
                })
                return false;//阻止表单提交
            })
        })
    </script>

</body>
</html>
